package Ajedrez.visual.Tablero;

import java.awt.*;
import javax.swing.*;

public class Casilla extends JPanel
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1300572379878539843L;
	
	Color color;
	public JLabel pieza;
	boolean marcada;
	
	public Casilla()
	{
		color = null;
		pieza = new JLabel();
		marcada = false;
	}
	
	public Casilla(boolean a)
	{
		if(a)
			color = Color.white;
		else
		{
			color = Color.black;
		}
		marcada = false;
		
		this.setBackground(color);
		this.setSize(70, 70);
		this.setPreferredSize(this.getSize());
		this.setBorder(BorderFactory.createLineBorder(Color.black, 1));
		
		setLayout(new BorderLayout());
		pieza = new JLabel();
		this.add(pieza);
	}
	
	public JLabel getPieza()
	{
		return pieza;
	}
	
	public void setPieza(ImageIcon i)
	{
		pieza.setIcon(i);
	}

	public static long getSerialversionuid()
	{
		return serialVersionUID;
	}

	public Color getColor()
	{
		return color;
	}

	public void setColor(Color color)
	{
		this.color = color;
	}
	
	public void iluminar(boolean a)
	{
		if(a)
			this.setBackground(new Color(0, 220, 220));
		else
			this.setBackground(color);
	}
	
	public void marcar(boolean a)
	{
		if(a)
		{
			this.setBackground(new Color(100, 255, 90));
			marcada = true;
		}
		else
		{
			this.setBackground(color);
			marcada = false;
		}
	}
	public boolean isMarcada()
	{
		return marcada;
	}
	
	public static void main(String[] args)
	{
		Casilla c = new Casilla(true);
		c.setPieza(new ImageIcon("resources/images/Piezas/PeonBlanco.png"));
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.add(c);
		f.setSize(c.getSize());
		f.setVisible(true);
	}
}
